#!/bin/bash

can_port_num=2

# Default bitrate : 500 Kbps
# Default dbitrate:   5 Mbps
let bitrate=500*1000
let dbitrate=5*1000*1000

if [[ -n $1 ]]; then
	can_port_num=$1
fi

echo -e "CAN Port Num: ${can_port_num}"
echo -e "CAN bitrate : ${bitrate}"
echo -e "CAN dbitrate: ${dbitrate}\n"

for (( i = 0; i < ${can_port_num}; i++ )); do
	echo -e ">>> Initialize CAN Port ${i}"
	sudo ip link set can${i} down
	sudo ip link set can${i} type can bitrate ${bitrate} \
		dbitrate ${dbitrate} berr-reporting on fd on
	sudo ip link set can${i} up
done

exit 0
